import request from "@/utils/request";

enum API {
  //获取全部的职位接口
  ALLROLE_URL = '/admin/acl/role/',
  //新增岗位的接口地址
  ADDROLE_URL = '/admin/acl/role/save',
  //更新已有的职位
  UPDATEROLE_URL = '/admin/acl/role/update',
  //删除已有的职位
  REMOVEROLE_URL = '/admin/acl/role/remove/',
  //获取全部的菜单与按钮的数据
  ALLPERMISSTION = '/admin/acl/permission/toAssign/',
  //给相应的职位分配权限
  SETPERMISTION_URL = '/admin/acl/permission/doAssign/?',
}

// 获取全部职位接口
export const getAllRole = (page: number, limit: number, roleName: string) => request.get(API.ALLROLE_URL + `${page}/${limit}/?roleName=${roleName}`)

// 新增或修改当前已有的角色
export const addOrUpdateRole = (data: any) => {
  if (data.id) {
    return request.put(API.UPDATEROLE_URL, data)
  } else {
    return request.post(API.ADDROLE_URL, data)
  }
}
// 删除已有的角色
export const removeRoleAPI = (roleId: number) => request.delete(API.REMOVEROLE_URL + roleId)
// 获取全部菜单权限接口
export const getAllPermissionMenu = (roleId: number) => request.get(API.ALLPERMISSTION + roleId)
// 将修改的职位保存
export const savePermissionRole = (roleId: number, permissionId: number[]) => request.post(API.SETPERMISTION_URL + `roleId=${roleId}&permissionId=${permissionId}`)